﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using DAL.Entities;

namespace DAL.EntitiesDAL
{
    public class nhanvien_DAL:BaseDAL,UTL.IBaseDAL 
    {

        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            string sql = @" SELECT * FROM NHANVIEN";
            return ExecuteQuery(sql);
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            string sql = @"DELETE FROM NHANVIEN WHERE MANV = '{0}'";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (nhanvien)obj;
            string sql = @"INSERT INTO NHANVIEN(MANV,HOTEN,DIACHI,DIENTHOAI,NGAYVAOLAM,SONGAYLAM,LUONG,PHAI,NGAYSINH,CA) VALUES('{0}',N'{1}',N'{2}',N'{3}',N'{4}',N'{5}',N'{6}',N'{7}',N'{8}',N'{9}') ";
            sql = string.Format(sql, o.MANV, o.HOTEN, o.DIACHI, o.DIENTHOAI, o.NGAYVAOLAM, o.SONGAYLAM, o.LUONG, o.PHAI, o.NGAYSINH, o.CA);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (nhanvien)obj;
            string sql = @"SET dateformat dmy;UPDATE NHANVIEN SET HOTEN=N'{1}',DIACHI=N'{2}',DIENTHOAI=N'{3}',NGAYVAOLAM=N'{4}',SONGAYLAM=N'{5}',LUONG=N'{6}',PHAI=N'{7}',NGAYSINH=N'{8}',CA=N'{9}' WHERE MANV='{0}'";
            sql = string.Format(sql, o.MANV, o.HOTEN, o.DIACHI, o.DIENTHOAI, o.NGAYVAOLAM, o.SONGAYLAM, o.LUONG, o.PHAI, o.NGAYSINH, o.CA);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            throw new NotImplementedException();
        }
        public string count_()
        {
            string sql = @"SELECT COUNT(MANV) as id FROM NHANVIEN";
            var tb = ExecuteQuery(sql);
            return tb.Rows.Count > 0 ? tb.Rows[0]["id"] + "" : "0";
        }
    }
}
